package com.ass.zookeeper.base;


import org.I0Itec.zkclient.exception.ZkMarshallingError;
import org.I0Itec.zkclient.serialize.ZkSerializer;

import java.io.UnsupportedEncodingException;

public class CustomerSerializer implements ZkSerializer {


    private String charset="UTF-8";

    public CustomerSerializer() {
    }

    public CustomerSerializer(String charset) {
        this.charset = charset;
    }

    //序列号
    @Override
    public byte[] serialize(Object o) throws ZkMarshallingError {
        byte[] bytes=null;
        try {
            bytes=String.valueOf(o).getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return bytes;
    }
    //反序列化
    @Override
    public Object deserialize(byte[] bytes) throws ZkMarshallingError {
        String result=null;
        try {
            result=new String(bytes,charset);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
}

